/**
 * 
 */
package pl.kkalisz.android.model.window;
import pl.kkalisz.android.model.error.uWindowNotFoundException;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;


/**
 * @author kkalisz
 *
 */
public class uWindowBuilder {

    Intent mIntent;
    private Integer mWindowId = -1;
    private boolean mCloseParrentWindow = false;
    private Activity mParrentActivity;




    /**
     * @param aParentActivity - parrent activity
     * @param aWindowId - id of Windows to launch see BngWindows
     * @param aCloseParrentActivity - is true Parrent activity is closed before staring new Activity
     * @throws uWindowNotFoundException 
     */
    public uWindowBuilder(Activity aParentActivity, Integer aWindowId, boolean aCloseParrentActivity) throws uWindowNotFoundException 
    {

        mParrentActivity = aParentActivity;
        mWindowId = aWindowId;
        mCloseParrentWindow = aCloseParrentActivity;
        try 
        {
            mIntent = new Intent(mParrentActivity, uWindowResolver.getWindowClass(aWindowId));
        } 
        catch (uWindowNotFoundException e) 
        {
            //e.printStackTrace(aParentActivity);
            mIntent = null;
            throw e;
        }


    }

    /**
     * @param aParentActivity - parrent activity
     * @param aWindowId - id of Windows to launch see BngWindows
     * @throws uWindowNotFoundException 
     */
    public uWindowBuilder(Activity aParentActivity, Integer aWindowId) throws uWindowNotFoundException 
    {
        this(aParentActivity, aWindowId, false);
    }

    /**
     * launch window
     */
    public void show()
    {
        if(mIntent!=null) uWindowResolver.launch(this);
    }

    /**
     * @return parrent/actual aCtivity
     */
    public Activity getParrent()
    {
        return mParrentActivity;
    }

    /**
     * @return id of Window to create
     */
    public Integer getWindowId()
    {
        return mWindowId;
    }
    
    /**
     * @return Intent used to start show new Window
     */
    public Intent getIntent()
    {
        return mIntent;
    }
    
    /**
     * @param aClose - indicates that current activity should e closed after opening new Window
     */
    public void closeCurrentWindow(boolean aClose)
    {
        mCloseParrentWindow = aClose;
    }
    
    public boolean shouldCloseCurrentWindow()
    {
        return mCloseParrentWindow;
    }



}
